#pragma once
#include "../zhelpers.h"
#include <map>
#include <string>
#include "thread.h"
#include "data.h"

using std::string;
using std::vector;

class address{
	public:
	string _ip;
	string _port;
	address(){};
	address(string ip, string port){_ip = ip; _port=port;}
	address &operator=(const address &s){_ip=s._ip;_port=s._port;}

	void set_address(string ip,string port){_ip = ip;_port = port;}
	void set_ip(string ip){_ip = ip;}
	void set_port(string port){_port = port;}

	string get_ip(){return _ip;}
	string get_port(){return _port;}
};

class server : private thread
{
	string _name;
	address _front_addr;
	address _back_addr;

	void *_zmq;
	void *_zmq_front;
	void *_zmq_back;

	thread_pool *_thread_pool;

	public:
	server(){_zmq = NULL;_zmq_front = NULL;_zmq_front = NULL;_thread_pool = new thread_pool(this);}

	virtual ~server(){};//delete thread_pool, destroy zmq
	void set_name(string name){_name = name;}
	void set_name(char *name){_name = name;}
	string get_name(){return _name;}

	void set_front_address(address addr){_front_addr = addr;}
	void set_back_address(address addr){_back_addr = addr;}
	address get_front_address(){return _front_addr;}
	address get_back_address(){return _back_addr;}

	void set_zmq(void *p){ _zmq = p;}
	void set_zmq_front(void *p){ _zmq_front = p;}
	void set_zmq_back(void *p){ _zmq_back = p;}
	
	void *get_zmq(){return _zmq;}
	void *get_zmq_front(){return _zmq_front;}
	void *get_zmq_back(){return _zmq_back;}
	
	void set_thread_pool(thread_pool *tp){_thread_pool = tp;}
	thread_pool *get_thread_pool(){return _thread_pool;}

	void set_thread_num(int i){get_thread_pool()->set_thread_num(i);}
	
	virtual int start(){return thread::start();}
	
	int thread_func();
};


class match_server : public server
{
	server *_extract_server;
	database_bdb *_db;

	public:
	match_server(){_extract_server = NULL;_db = NULL;}

	void add_extract_server(server *s){_extract_server = s;}
	server *get_extract_server(){return _extract_server;}

	void set_database(database_bdb *db){_db = db;}
	database_bdb *get_database(){return _db;}
};










